﻿using FluentAssertions;
using Sustainalytics.BusinessResearchProductStates.Entities.ResearchState;
using Sustainalytics.Entities;
using Sustainalytics.Entities.ScreeningTool;
using Sustainalytics.ScreeningTool.Synchronization.Caches;
using Sustainalytics.ScreeningTool.Synchronization.Entities;
using System.Linq;
using Xunit;

namespace Sustainalytics.ScreeningTool.Synchronization.Tests.Dictionaries.FieldDefinitionsCacheTests
{
    [Trait("Category", "Unit")]
    public class IsResearchAvailable_Should
    {
        private const string Field1 = "Field1";
        private const string Field2 = "Field2";
        private const string Field3 = "Field3";

        private readonly FieldDefinitionsCache _fieldDefinitionsCache = new FieldDefinitionsCache
        {
            { Field1, new FieldDefinition { ResearchProducts = null } },
            { Field2, new FieldDefinition { ResearchProducts = Enumerable.Empty<ResearchProduct>() } },
            { Field3, new FieldDefinition { ResearchProducts = new[] { ResearchProduct.Core } } },
        };

        [Fact]
        public void Return_false_when_researchStates_is_null()
            => _fieldDefinitionsCache.IsResearchAvailable(Field1, researchStates: null).Should().Be(false);

        [Fact]
        public void Return_false_when_field_is_not_found()
            => _fieldDefinitionsCache.IsResearchAvailable("not found", new ResearchStates()).Should().Be(false);

        [Fact]
        public void Return_true_when_field_research_products_is_null()
            => _fieldDefinitionsCache.IsResearchAvailable(Field1, new ResearchStates()).Should().Be(true);

        [Fact]
        public void Return_true_when_field_research_products_is_empty()
            => _fieldDefinitionsCache.IsResearchAvailable(Field2, new ResearchStates()).Should().Be(true);

        [Fact]
        public void Return_false_when_research_state_is_not_ResearchAvailable()
            => _fieldDefinitionsCache.IsResearchAvailable(Field3, new ResearchStates { CoreEsg = ResearchState.FrameworkNotApplicable }).Should().Be(false);

        [Fact]
        public void Return_true_when_research_state_is_ResearchAvailable()
            => _fieldDefinitionsCache.IsResearchAvailable(Field3, new ResearchStates { CoreEsg = ResearchState.ResearchAvailable }).Should().Be(true);
    }
}
